package com.google.code.swingonfire.utility.date;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;

public class DateRenderInfoRFC822TimeZonePart extends AbstractDateRenderInfoPart
{

    public DateRenderInfoRFC822TimeZonePart(int length)
    {
        super(4);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getValue(Calendar calendar, DateFormatSymbols dateFormatSymbols, Locale locale)
    {
        int value = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000;
        int num = ((value / 60) * 100) + (value % 60);

        String result = formatNumber(num);

        if (!result.startsWith("-"))
        {
            result = "+" + result;
        }

        return result;
    }

}
